home *** CD-ROM | disk | FTP | other *** search
-
- #include <A4Stuff.h>
- #include <SetUpA4.h>
- #include <Traps.h>
- #include <MacWindows.h>
- #include <QuickDraw.h>
- #include <Resources.h>
- #include <Sound.h>
- #include <LowMem.h>
-
- #define SOUND 1
-
- typedef pascal OSErr (*PostEventType)(short eventNum:__a0,long eventMsg:__d0):__d0;
- PostEventType oldPostEvent;
-
- typedef pascal void (*ProcessMgrDispatchType)(short selector);
- ProcessMgrDispatchType oldProcessMgrDispatch;
-
- #if SOUND
- SndListHandle sound;
- SndChannelPtr chan;
- #endif
-
- static pascal OSErr myPostEvent2(short eventNum,long eventMsg)
- {
- short resultCode = noErr;
- Boolean doIt = true;
- Rect windowRect;
-
- EnterCallback();
-
- if ( eventNum == mouseDown )
- {
- WindowPeek frontWindow = (WindowPeek) LMGetWindowList();
- if ( frontWindow )
- {
- //The following code is dereferencing a handle at interupt time. This will
- //do bad things for you if you think you can use this code for your own
- //purposes.
- windowRect = (*frontWindow->strucRgn)->rgnBBox;
- if ( !PtInRect( LMGetRawMouseLocation(), &windowRect ) )
- {
- InsetRect( &windowRect, -10, 0 );
- if ( PtInRect( LMGetRawMouseLocation(), &windowRect ) )
- {
- #if SOUND
- if ( sound && chan )
- SndPlay( chan, sound, true );
- else
- Debugger();
- #endif
- doIt = false;
- }
- }
- }
- }
-
- if (doIt)
- resultCode = (oldPostEvent)(eventNum, eventMsg);
- ExitCallback();
- return resultCode;
- }
-
- asm static pascal OSErr myPostEvent(short eventNum,long eventMsg)
- {
- movem.l d1-d3/a0-a3,-(a7)
- clr.w -(a7)
- move.w a0,-(a7)
- move.l d0,-(a7)
- jsr myPostEvent2
- move.w (a7)+,d0
- movem.l (a7)+,d1-d3/a0-a3
- rts
- }
-
-
- static pascal void myWatchForProcessMgr(short selector)
- {
- ProcessMgrDispatchType localTrapAddress;
-
- EnterCodeResource();
-
- if (selector == 1)
- {
- // install findwindow patch here
- oldPostEvent = (PostEventType)GetOSTrapAddress( _PostEvent );
- SetOSTrapAddress( (UniversalProcPtr)myPostEvent, _PostEvent );
- }
-
- localTrapAddress = oldProcessMgrDispatch;
- ExitCodeResource();
-
- (*oldProcessMgrDispatch)(selector);
- }
-
- void main( void )
- {
- Handle myHandle;
-
- EnterCodeResource();
- PrepareCallback();
-
- SetZone( SystemZone() );
- myHandle = Get1Resource( 'INIT', 300 );
-
-
- DetachResource( myHandle );
- HLock( myHandle );
-
- #if SOUND
- sound = (SndListHandle)Get1Resource( 'snd ', 8192 );
- DetachResource( (Handle)sound );
- HLock((Handle)sound);
- SndNewChannel( &chan, 0, 0, nil );
- SndPlay( chan, sound, true );
- #endif
-
- oldProcessMgrDispatch = (ProcessMgrDispatchType)GetToolTrapAddress( 0xABCF );
- SetToolTrapAddress( (UniversalProcPtr)myWatchForProcessMgr, 0xABCF );
-
- ExitCodeResource();
- }
-